package compressString;
public class Solution {
    public String compressString(String s) {
        //
        if(s.length() == 0)return "";
        int i = 0,n = s.length();
        StringBuilder sb = new StringBuilder();
        char c = s.charAt(0);
        int count = 0;
        while (i<n) {
            if(s.charAt(i) == c) {
                if(i == n-1) {
                    count++;
                    sb.append(c).append(count);
                    break;
                } else {
                    i++;
                    count++;
                }
            } else {
                sb.append(c).append(count);
                count = 0;
                c = s.charAt(i);
                //  i++;
            }
        }
        if(sb.length()>=s.length()){
            return s;
        }
        return sb.toString();
    }
}
